package com.superWindCloud.learn_java;

public final class Main {
    public static void main(String[] args) {
        RingCache<Object> cache = new RingCache<>(5);
        Runnable writer = () -> {
            for (int i = 0; i < 5; i++) {
                cache.put(i);
                var value = "superWindCloud" + i;
                cache.put(value);
                System.out.println("写入: " + i);
                System.out.println("写入: " + value);

            }
        };


        var writerThread = new Thread(writer);
        writerThread.start();
        try {
            writerThread.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        for (int i = 0; i <  cache.capacity() ; i++) {
            var value = cache.get();
            System.out.println("读取: " + value);
        }

    }

    public static void readFile(String fileName) {
        try {

            java.io.File file = new java.io.File(fileName);
            java.io.FileReader fileReader = new java.io.FileReader(file);
            // Read the file
            char[] buffer = new char[1024];
            int length;
            while ((length = fileReader.read(buffer)) != -1) {
                System.out.println(new String(buffer, 0, length));
            }
            // Close the file
            fileReader.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
}